/**
 * 
 */
package br.com.binding.client.event;

import java.util.ArrayList;
import java.util.List;

/**
 * An Utility class thar hides all the listeners management.

 * @author Marcelo Emanoel
 */
public class PropertyChangeSupport {
	
	private Object source;
	private List<PropertyChangeListener> listeners;
	
	public PropertyChangeSupport(Object source){
		this.listeners = new ArrayList<PropertyChangeListener>();
		this.source = source;
	}
	
	public void addPropertyChangeListener(PropertyChangeListener listener){
		listeners.add(listener);
	}
	
	public void removePropertyChangeListener(PropertyChangeListener listener){
		listeners.remove(listener);
	}
	
	public void firePropertyChange(String propertyName, Object oldValue, Object newValue){
		for(PropertyChangeListener listener : listeners){
			listener.propertyChanged(new PropertyChangeEvent(source, propertyName, oldValue, newValue));
		}
	}
}
